package com.funny.stock.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;

import javax.sql.DataSource;

@Configuration
@EnableJpaRepositories(basePackages =  "com.funny.stock",
        entityManagerFactoryRef = "entityManagerFactory")
public class RepositoryConfig {

    @Autowired
    private DataSource dataSource;

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(
            EntityManagerFactoryBuilder builder) {
        return builder
                .dataSource(dataSource)
                .packages("com.funny.stock")
                .build();
    }

//    @Bean
//    public PlatformTransactionManager transactionManager(EntityManagerFactory factory){
//        JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
//        jpaTransactionManager.setDataSource(dataSource);
//        jpaTransactionManager.setEntityManagerFactory(factory);
//        return jpaTransactionManager;
//    }

//    @Bean
//    public RedisCacheConfiguration cacheConfiguration() {
//        RedisCacheConfiguration cacheConfig = RedisCacheConfiguration.defaultCacheConfig()
//                .entryTtl(Duration.ofSeconds(3600))
//                .disableCachingNullValues();
//        return cacheConfig;
//    }

}
